home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / highlight / highlight-W32GUI-2.2-10b-Setup.exe / {app} / src / gui.h < prev    next >
C/C++ Source or Header  |  2005-03-20  |  9KB  |  275 lines

  1. /***************************************************************************
  2.                           gui.h  -  description
  3.                              -------------------
  4.     begin                : 06.08.02 
  5.     copyright            : (C) 2002 by AndrΘ Simon
  6.     email                : andre.simon1@gmx.de
  7.  ***************************************************************************/
  8.  
  9. /***************************************************************************
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  ***************************************************************************/
  17.  
  18.  
  19. #ifndef __gui_H__
  20. #define __gui_H__
  21.  
  22. // For compilers that support precompilation, includes "wx/wx.h".
  23. #include "wx/wxprec.h"
  24.  
  25. // Include wxWindows' headers
  26. #ifndef WX_PRECOMP
  27.     #include <wx/wx.h>
  28. #endif
  29.  
  30. #include <wx/dir.h>
  31. #include <wx/timer.h>
  32. #include <wx/dnd.h>
  33. #include <wx/filename.h>
  34. #include <wx/cmdline.h>
  35. #include <wx/utils.h>
  36. #include <wx/tipdlg.h>
  37. #include <wx/spinctrl.h>
  38. #include <wx/statline.h>
  39. #include <wx/combobox.h>
  40.  
  41. #include <string>
  42. #include <stdlib.h>
  43. #include <windows.h>
  44. #include <iostream>
  45. #include <fstream>
  46. #include <set>
  47. #include <sstream>
  48. #include <vector>
  49.  
  50. #include "version.h"
  51. #include "codegenerator.h"
  52. #include "configurationreader.h"
  53. #include "datadir.h"
  54. #include "enums.h"
  55. #include "platform_fs.h"
  56.  
  57. #define MSG_INFO_TXT "Highlight for Windows %s\n(C) 2002-2005 AndrΘ Simon\
  58.  <andre.simon1@gmx.de>\n\nArtistic Style Classes\n(C) 1998-2002 Tal Davidson\
  59.  <davidsont@bigfoot.com>\n\nBuilt with WxWidgets %d.%d.%d\n\nTranslators:\n\n\
  60. %s\
  61. \nReleased under the terms of the GNU GPL license.\
  62. \n\nUpdates and source code: %s"
  63.  
  64. #define CSS_DEFAULT_NAME "highlight.css"
  65.  
  66. #define NUMBER_FORMATS 7
  67. #define NUMBER_ENCODINGS 15
  68.  
  69.  
  70. // The main Application
  71. class HighlightApp: public wxApp
  72. {
  73.   public:
  74.       virtual bool OnInit();
  75. };
  76.  
  77.  
  78. typedef map<string, string> ExtensionsMap;
  79.  
  80.  
  81. // The main Window
  82. class HighlightFrame : public wxFrame
  83. {
  84.  public:
  85.    HighlightFrame(const wxString &title);
  86.  
  87.   // Event handler (should *NOT* be virtual!)
  88.    void OnQuit(wxCommandEvent &event);
  89.   // void OnQuit2(wxCloseEvent &event);
  90.    void OnClickButtonSource(wxCommandEvent &event);
  91.    void OnClickButtonTargetDir(wxCommandEvent &event);
  92.    void OnClickButtonClear(wxCommandEvent &event);     
  93.    void OnClickButtonRemSelection(wxCommandEvent &event);     
  94.    void OnClickButtonOpenStyleFile(wxCommandEvent &event);
  95.    void OnClickButtonStart(wxCommandEvent &event);
  96.    void OnHelp(wxCommandEvent &event);
  97.    void OnAbout(wxCommandEvent &event);
  98.    void OnLicense(wxCommandEvent &event);
  99.    void OnChangelog(wxCommandEvent &event); 
  100.    void OnTips (wxCommandEvent &event); 
  101.    void OnCheckLanguage(wxCommandEvent &event);  
  102.    void OnStyleOutfileChanged  (wxCommandEvent &event);
  103.        
  104.    void addInputFiles(const wxArrayString& inputFiles, const wxString& prefix);   
  105.    void showStartupTips(bool forceTips=false);
  106.    
  107.    void showPopupMenu(const wxPoint & pos);
  108.    
  109.    bool getFatalError(){ return fatalError; } 
  110.    
  111.  private:   
  112.     bool fatalError;          
  113.     bool writePreferences();
  114.     bool loadLanguage(const string &lang);
  115.     bool loadFileExtensions();
  116.     bool applyPreferences();
  117.     void plausiChecks();     
  118.     void showTextFile(const wxString &file);
  119.     string readFile(const string &path, bool keepNewLine=false);    
  120.     
  121.     string getOutFileSuffix();
  122.     string getFileType(const string& suffix);
  123.     string getFileSuffix(const string& fileName);     
  124.  
  125.     highlight::WrapMode getWrappingStyle();  
  126.     highlight::OutputType getOutputType();
  127.  
  128.     void SetStyleInLabel();
  129.     void assignToolTip(wxWindow* widget, const char* tipName);
  130.     void fillChoiceCtrl(wxChoice* choice, const wxString &dir, const wxString &ext);     
  131.     void checkStyleReferences(wxTextCtrl *styleCtrl, bool webOutput);
  132.          
  133.     ExtensionsMap extensions;        
  134.     
  135.     string preferencesPath;
  136.     wxString openFileDir, formatMsg, fileFilter;        
  137.     wxString outputFormats[NUMBER_FORMATS];
  138.     wxString encodings[NUMBER_ENCODINGS];
  139.  
  140.     wxPanel    *panel;
  141.     wxButton   *butSource, *butClearList, *butRemoveSelection;
  142.     wxButton   *butOutDir;
  143.     wxButton   *butStart;
  144.     wxButton   *butChooseStyleInfile;    
  145.     wxListBox  *listBox ;
  146.     wxChoice   *themeChoice,
  147.                *formatChoice;
  148.     wxComboBox *encodingChoice;
  149.     wxTextCtrl *outDir, 
  150.                *styleOutFileName,
  151.                *styleInFileName;
  152.     wxRadioBox *outputFormat;
  153.     wxCheckBox *includeStyle,
  154.                *fragment,
  155.                *linenumbers,
  156.                *attachAnchors,
  157.                *reformatCode,
  158.                *generateHtmlIndex,
  159.                *wrapLines,
  160.                *wrapLinesCautious,
  161.                *replaceLatexQuotes,
  162.                *lnFillZeroes,
  163.                *writeToSourceDir,
  164.                *useEncoding;
  165.                
  166.     wxSpinCtrl *tabWidth;
  167.     wxStaticText *lblStyleOut, *lblColourTheme, *lblStyleIn, *lblOutDir, *lblTabWidth;
  168.     wxMenu *menu1, *menu3, *menu2;
  169.     wxMenuBar *MenuBar;
  170.     
  171.     bool showTips;
  172.     int lastTip;
  173.     
  174.     wxGauge *progress;
  175.     string language;
  176.     ConfigurationReader *i18n, *prefConf;
  177.     
  178.     DataDir dataDir;
  179.             
  180.     // Any class wishing to process wxWindows events must use this macro
  181.     DECLARE_EVENT_TABLE()            
  182. };
  183.    enum 
  184.    {
  185.     PROGRAM_QUIT = wxID_HIGHEST+1,
  186.     ID_MENU_OPENFILES,
  187.     ID_BUTTON_OPENFILES,
  188.     ID_BUTTON_OPEN_CSS_INFILE,
  189.     ID_MENU_HELP,
  190.     ID_MENU_ABOUT,
  191.     ID_MENU_CHANGELOG,
  192.     ID_MENU_LICENSE,        
  193.     ID_MENU_TIPS,        
  194.     ID_BUTTON_OUTDIR, 
  195.     ID_LISTBOX,        
  196.     ID_OUTDIRTEXT,
  197.     ID_INCLUDECSS,
  198.     ID_OUTPUTFORMAT,
  199.     ID_START,
  200.     ID_INCLUDELINENUMBERS,
  201.     ID_FRAGMENT,
  202.     ID_STYLE,
  203.     ID_BUTTON_CLEAR,
  204.     ID_PROGRESS,
  205.     ID_THEMECHOICE,
  206.     ID_ATTACHANCHORS,
  207.     ID_CSS_INFILE,
  208.     ID_CSS_OUTFILE,
  209.     ID_REFORMATCODE,
  210.     ID_FORMATCHOICE,
  211.     ID_GENERATEINDEX,
  212.     ID_WRAP,
  213.     ID_WRAP_CAUTIOUS,
  214.     ID_REPLACE_QUOTES,
  215.     ID_TAB_WIDTH,
  216.     ID_FILL_ZEROES,
  217.     ID_WRITE_TO_SRCDIR,    
  218.     ID_PANEL,
  219.     ID_BUTTON_REMOVE,
  220.     ID_USE_ENCODING,
  221.     ID_ENCODING_LIST,
  222.     // This id is used to calculate menu ids at runtime:        
  223.     ID_MENU_LANGUAGE_DYN = wxID_HIGHEST + 100
  224.     };
  225.  
  226. BEGIN_EVENT_TABLE(HighlightFrame, wxFrame)  
  227.    EVT_MENU(PROGRAM_QUIT, HighlightFrame::OnQuit)
  228.    EVT_CLOSE(HighlightFrame::OnQuit)
  229.    EVT_MENU(ID_MENU_OPENFILES, HighlightFrame::OnClickButtonSource)   
  230.    EVT_MENU(ID_MENU_HELP, HighlightFrame::OnHelp)
  231.    EVT_MENU(ID_MENU_ABOUT, HighlightFrame::OnAbout)
  232.    EVT_MENU(ID_MENU_LICENSE, HighlightFrame::OnLicense)
  233.    EVT_MENU(ID_MENU_CHANGELOG, HighlightFrame::OnChangelog)      
  234.    EVT_MENU(ID_MENU_TIPS, HighlightFrame::OnTips)      
  235.    EVT_BUTTON(ID_BUTTON_OPENFILES, HighlightFrame::OnClickButtonSource)
  236.    EVT_BUTTON(ID_BUTTON_OUTDIR, HighlightFrame::OnClickButtonTargetDir)
  237.    EVT_BUTTON(ID_START, HighlightFrame::OnClickButtonStart)
  238.    EVT_BUTTON(ID_BUTTON_OPEN_CSS_INFILE, HighlightFrame::OnClickButtonOpenStyleFile)   
  239.    EVT_BUTTON(ID_BUTTON_CLEAR, HighlightFrame::OnClickButtonClear)  
  240.    EVT_BUTTON(ID_BUTTON_REMOVE , HighlightFrame::OnClickButtonRemSelection)  
  241.    EVT_CHECKBOX(ID_INCLUDECSS, HighlightFrame::plausiChecks)
  242.  
  243.    EVT_CHECKBOX(ID_INCLUDELINENUMBERS, HighlightFrame::plausiChecks)   
  244.    EVT_RADIOBOX(ID_OUTPUTFORMAT, HighlightFrame::plausiChecks)
  245.    EVT_CHECKBOX(ID_REFORMATCODE, HighlightFrame::plausiChecks)
  246.    EVT_CHECKBOX(ID_WRAP, HighlightFrame::plausiChecks)   
  247.    EVT_CHECKBOX(ID_WRAP_CAUTIOUS, HighlightFrame::plausiChecks) 
  248.    EVT_CHECKBOX(ID_FRAGMENT, HighlightFrame::plausiChecks)  
  249.    EVT_CHECKBOX(ID_WRITE_TO_SRCDIR, HighlightFrame::plausiChecks)      
  250.    EVT_CHECKBOX(ID_USE_ENCODING, HighlightFrame::plausiChecks)    
  251.    EVT_TEXT(ID_CSS_OUTFILE, HighlightFrame::OnStyleOutfileChanged)
  252. END_EVENT_TABLE()
  253.  
  254. //BEGIN_EVENT_TABLE(MouseEvtHandler, wxEvtHandler)
  255. //     EVT_RIGHT_DOWN(MouseEvtHandler::OnRightMouseDown)
  256. //END_EVENT_TABLE()
  257.  
  258. IMPLEMENT_APP(HighlightApp)
  259.  
  260.  
  261. /* Drag and Drop Class*/
  262. class DropFiles: public wxFileDropTarget {
  263. public:    
  264.     DropFiles (HighlightFrame *frame) {m_frame = frame;}
  265.     virtual bool OnDropFiles (wxCoord x, wxCoord y, 
  266.                               const wxArrayString& filenames);
  267. private:
  268.     HighlightFrame *m_frame;
  269. };
  270.  
  271.  
  272.  
  273. #endif
  274.  
  275.